<style>
 .inputDiv input{
 font-size: 14px;}
 .inputDiv b{
 font-weight: normal;
 }
 .layui-layer-title{
 font-size: 16px;
 } 
</style>
[#if !(user??) ]
<link href="/res/css/common/login.css" rel="stylesheet">
<div style="width: 350px; height: 330px; position: absolute; background: white; overflow: hidden;" id="loginWin">
    <div class="inputDiv loginForm" style="left: 25px;top: 0px;">
        <h6>账号登录</h6>
        <small style="visibility: hidden;" id="loginErrorInWin">
            <img src="/res/images/oparaStatus/noticeCl_11.jpg"/>
            <span style="margin-left: 10px;"></span>
        </small>
        <div style="padding-left: 0px;overflow: hidden;border:1px solid #cfcfcf;">
            <input type="text" autocomplete="off" placeholder="手机/邮箱" name="username" style="border: none;" onkeyup="enterLoginWin()"/>
            <img class="telLogin" src="/res/images/common/a_11.jpg"/>
        </div>
        <div style="padding-left: 0px;overflow: hidden;border:1px solid #cfcfcf;"> 
            <input type="text" placeholder="密码" name="password" autocomplete="off" style="border: none;" onkeyup="enterLoginWin()"  onfocus="txToPass(this)"/>
            <img class="passReg" src="/res/images/common/a_14.jpg"/>
        </div>
        <em style="padding-left: 0px;">
			<span class="checkSwitch" style="display: inline-block; width: 15px; height: 15px;">
				<img src="/res/images/checkBoxRadio/noCheck.jpg" onclick="read(this)" style="display:none;vertical-align: middle;" data-id="rememberMe" data-value="false"/>
				<img src="/res/images/checkBoxRadio/a_18.jpg" onclick="read(this)" data-id="rememberMe" data-value="true" style="vertical-align: middle;"/>
			</span>
            <input type="hidden" name="rememberMe" value="true"/>
            下次自动登录
            <a href="/user/iforgot" style="color:#00ceff;float: right;" target="_blank">忘记密码？</a>
        </em>
        <button type="button" onclick="loginInWin()">登录</button>
        <b>还没有账号？<a href="/user/register" target="_blank" style="color:#00b1db;">立即注册</a></b>
    </div>
</div>

<script type="text/javascript" src="/res/js/common/util.js"></script>
<script src="/res/third/nice-validator/jquery.validator.min.js?local=zh-CN"></script>
<script type="text/javascript">
    function showLoginErrorInWin(msg) {
        $('#loginErrorInWin span').html(msg);
        $('#loginErrorInWin').css("visibility","visible");
    }

    function read(o) {
        $(o).siblings("img").show();
        $(o).hide();
        var id = $(o).siblings("img").attr('data-id');
        var value = $(o).siblings("img").attr('data-value');
        $('#' + id).val(value);
    }
	function txToPass(o){
		$(o).attr("type","password");
	}
    function loginInWin() {
        var username = $.trim($('#loginWin input[name=username]').val());
        var password = $('#loginWin input[name=password]').val();
        var rememberMe = $('#loginWin input[name=rememberMe]').val();

        if($.trim(username) == '') {
            showLoginErrorInWin('请输入手机号或邮箱');
            return;
        }
        if($.trim(password) == '') {
            showLoginErrorInWin('请输入密码');
            return;
        }
        if(!isMobile(username) && !isEmail(username)) {
            showLoginErrorInWin("请输入手机号或邮箱");
            return;
        }

        $.ajax({
            url : '/user/login',
            type : 'post',
            dataType : "json",
            data : {username : username, password : password, rememberMe : rememberMe},
            beforeSend : function() {
                layer.load(2, {shade: 0.1});
            },
            success : function(data) {
                if(data.success) {
                    [#if callback?? ]
                        ${callback}(data);
                    [#else]
                        location.reload();
                    [/#if]

                    layer.closeAll('page');


                } else {
                    if(data.obj) {
                        window.location.href = data.obj;
                    } else {
                        showLoginErrorInWin(data.msg);
                    }
                }
            },
            error : function() {
                showLoginErrorInWin("登录失败");
            },
            complete : function() {
                layer.closeAll('loading');
            }
        });
    }

    function enterLoginWin() {
        if(event.keyCode == 13) {
            loginInWin();
        }
    }
</script>
[#else]
<script>

    [#if callback?? ]
    ${callback}();
    [#else]
    location.reload();
    [/#if]
    layer.closeAll('page');
</script>
[/#if]